home *** CD-ROM | disk | FTP | other *** search
/ GFX Sensations 1 / Graphic Sensations - Volume 1.iso / tools / amiga / show / jpgagasr.lha / ppm2aga / DisplayGfx.c next >
Encoding:
C/C++ Source or Header  |  1994-05-08  |  4.5 KB  |  165 lines

  1. /* Screen display routines              */
  2. /* written by Günther Röhrich           */
  3. /* this source is Public Domain         */
  4.  
  5. /* this works only with OS 3.0 or higher */
  6.  
  7.  
  8. #define INTUI_V36_NAMES_ONLY
  9.  
  10. #include <exec/types.h>
  11. #include <intuition/intuition.h>
  12. #include <intuition/screens.h>
  13. #include <graphics/modeid.h>
  14.  
  15. #include <clib/intuition_protos.h>
  16. #include <clib/graphics_protos.h>
  17.  
  18. #ifndef __GNUC__
  19. #include <pragmas/intuition_pragmas.h>
  20. #include <pragmas/graphics_pragmas.h>
  21. #endif
  22.  
  23. #include "ppm2AGA.h"
  24.  
  25. extern struct Library *IntuitionBase;
  26. extern int VGAenable;
  27. struct Screen *my_screen = NULL;
  28. struct Window *my_window = NULL;
  29. struct RastPort temprp; /* a copy of the screen's RastPort */
  30.  
  31. void CloseDisplay(void);
  32.  
  33. /* Initialize the display, colors will be set later */
  34.  
  35. int InitDisplay(int cols, int rows, ULONG Mode, int NumPlanes)
  36. {
  37.   if(IntuitionBase->lib_Version >= 39)
  38.   {
  39.     ULONG Depth, DisplayID;
  40.  
  41.     /* Calculate a DisplayID */
  42.     /* this should be done better... */
  43.  
  44.     if(VGAenable)
  45.     {
  46.       if(Mode == HAM6 || Mode == HAM8)
  47.       {
  48.         if(cols > 370 || rows > 260)
  49.           DisplayID = VGAPRODUCTHAM_KEY;
  50.         else
  51.           DisplayID = VGALORESHAMDBL_KEY;
  52.       }
  53.       else
  54.       {
  55.         if(cols > 370 || rows >260) 
  56.           DisplayID = VGAPRODUCT_KEY;
  57.         else
  58.           DisplayID = VGALORESDBL_KEY; 
  59.           
  60.       }
  61.     }
  62.     else
  63.     {  
  64.       if(Mode == HAM6 || Mode == HAM8)
  65.         DisplayID = DEFAULT_MONITOR_ID | HAM_KEY;
  66.       else
  67.         DisplayID = DEFAULT_MONITOR_ID;
  68.  
  69.       if(cols > 370) DisplayID |= HIRES;
  70.       if(rows > 280) DisplayID |= LACE;
  71.     }
  72.  
  73.     if(Mode == HAM6) Depth = 6;
  74.     else if(Mode == HAM8) Depth = 8;
  75.     else Depth = NumPlanes;
  76.  
  77.     my_screen = OpenScreenTags(NULL, SA_Width,     (ULONG)cols,
  78.                                      SA_Height,    (ULONG)rows,
  79.                                      SA_Depth,     (ULONG)Depth,
  80.                                      SA_DisplayID, (ULONG)DisplayID,
  81.                                      SA_Type,      (ULONG)CUSTOMSCREEN,
  82.                                      SA_Quiet,     (ULONG)TRUE,
  83.                                      SA_AutoScroll,(ULONG)TRUE,
  84.                                      SA_Overscan,  (ULONG)OSCAN_STANDARD,
  85.                                      TAG_DONE);
  86.  
  87.     if(my_screen)
  88.     {
  89.       /* open a dummy window to allow autoscroll feature      */
  90.       /* if the window fails to open we can continue, but the */
  91.       /* user will not be able to move the screen             */
  92.       my_window = OpenWindowTags(NULL, WA_Left,         (ULONG)0,
  93.                                        WA_Top,          (ULONG)0,
  94.                                        WA_Width,        (ULONG)cols,
  95.                                        WA_Height,       (ULONG)rows,
  96.                                        WA_CustomScreen, my_screen,
  97.                                        WA_NoCareRefresh,(ULONG)TRUE,
  98.                                        WA_Borderless,   (ULONG)TRUE,
  99.                                        WA_Backdrop,     (ULONG)TRUE,
  100.                                        WA_RMBTrap,      (ULONG)TRUE, /* disable screen menu drawing */
  101.                                        TAG_DONE);
  102.  
  103.       /* initialize temprp for use with WritePixelLine8() */
  104.  
  105.       CopyMem(&my_screen->RastPort, &temprp, sizeof(struct RastPort));
  106.       temprp.Layer = NULL;
  107.       /* V39 function */
  108.       temprp.BitMap = AllocBitMap(cols, 1, my_screen->RastPort.BitMap->Depth, 0, my_screen->RastPort.BitMap);
  109.  
  110.       if(temprp.BitMap == NULL)
  111.       {
  112.         CloseDisplay();
  113.         return 0; /* failure */
  114.       }
  115.       return 1; /* success */
  116.     }
  117.   }
  118.   return 0; /* failure */
  119. }
  120.  
  121.  
  122. /* Set a color... */
  123.  
  124. void SetDisplayColor(int ColorNumber, UBYTE r, UBYTE g, UBYTE b)
  125. {
  126.   if(my_screen)
  127.     /* V39 function */
  128.     SetRGB32(&my_screen->ViewPort, (ULONG)ColorNumber, (ULONG)r << 24,
  129.                                                        (ULONG)g << 24,
  130.                                                        (ULONG)b << 24);
  131. }
  132.  
  133.  
  134. /* Close the display */
  135.  
  136. void CloseDisplay(void)
  137. {
  138.   if(temprp.BitMap)
  139.   {
  140.     /* V39 function */
  141.     FreeBitMap(temprp.BitMap);
  142.     temprp.BitMap = NULL;
  143.   }
  144.   if(my_window)
  145.   {
  146.     CloseWindow(my_window);
  147.     my_window = NULL;
  148.   }
  149.   if(my_screen)
  150.   {
  151.     CloseScreen(my_screen);
  152.     my_screen = NULL;
  153.   }
  154. }
  155.  
  156.  
  157. /* display a line of chunky pixel graphics... */
  158.  
  159. void DisplayRow(char *array, int cols, int row)
  160. {
  161.   if(my_screen)
  162.     /* V37 function */
  163.     WritePixelLine8(&my_screen->RastPort, 0, row, cols, array, &temprp);
  164. }
  165.